package com.lucky.common.init;

import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletContext;

//@Component
public class InitListener implements ApplicationListener<ContextRefreshedEvent> {
	
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {

//    	logger.info("--------- 执行 监听器，event：{}",event.getApplicationContext().getDisplayName());
        
        String displayName = event.getApplicationContext().getDisplayName();
        if(displayName.contains("FeignContext") || displayName.contains("SpringClientFactory")) {
            return;
        }
    	
        // 将 ApplicationContext 转化为 WebApplicationContext 
        WebApplicationContext webApplicationContext = (WebApplicationContext)event.getApplicationContext();
        // 从 webApplicationContext 中获取  servletContext 
        ServletContext application = webApplicationContext.getServletContext();
        // servletContext设置值
//        servletContext.setAttribute("key", "value");
        

        
    }
}
